<template>
    <div class="app-container">
        <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch"
                 label-width="68px">
            <el-form-item label="序号" prop="xuhao">
                <el-input v-model="queryParams.xuhao" placeholder="请输入序号"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="工序编码" prop="code">
                <el-input v-model="queryParams.code" placeholder="请输入工序编码"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="工序名称" prop="name">
                <el-input v-model="queryParams.name" placeholder="请输入工序名称"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="图纸号" prop="shuoming">
                <el-input v-model="queryParams.shuoming" placeholder="请输入图纸号"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="项目id" prop="projectId">
                <el-input v-model="queryParams.projectId" placeholder="请输入项目id"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="项目编号" prop="projectCode">
                <el-input v-model="queryParams.projectCode" placeholder="请输入项目编号"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="项目名称" prop="projectName">
                <el-input v-model="queryParams.projectName" placeholder="请输入项目名称"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="销售产品关联id" prop="saleId">
                <el-input v-model="queryParams.saleId" placeholder="请输入销售产品关联id"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="产品id" prop="goodsId">
                <el-input v-model="queryParams.goodsId" placeholder="请输入产品id"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="工艺id" prop="gongyiId">
                <el-input v-model="queryParams.gongyiId" placeholder="请输入工艺id"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="工序id" prop="gongxuId">
                <el-input v-model="queryParams.gongxuId" placeholder="请输入工序id"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="工艺编码" prop="gongyiCode">
                <el-input v-model="queryParams.gongyiCode" placeholder="请输入工艺编码"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="产品编码" prop="goodsCode">
                <el-input v-model="queryParams.goodsCode" placeholder="请输入产品编码"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="产品名称" prop="goodsName">
                <el-input v-model="queryParams.goodsName" placeholder="请输入产品名称"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="产品型号" prop="goodsModel">
                <el-input v-model="queryParams.goodsModel" placeholder="请输入产品型号"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
          <!--  <el-form-item label="型号明细" prop="goodsBrand">
                <el-input v-model="queryParams.goodsBrand" placeholder="请输入型号明细"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>-->
                        <el-form-item label="实际开始时间" prop="doStartTime">
                            <el-date-picker clearable v-model="queryParams.doStartTime"
                                            type="date" value-format="yyyy-MM-dd" placeholder="请选择实际开始时间">
                            </el-date-picker>
                        </el-form-item>
                        <el-form-item label="实际完成时间" prop="doEndTime">
                            <el-date-picker clearable v-model="queryParams.doEndTime"
                                            type="date" value-format="yyyy-MM-dd" placeholder="请选择实际完成时间">
                            </el-date-picker>
                        </el-form-item>
                        <el-form-item label="计划开始时间" prop="planStartTime">
                            <el-date-picker clearable v-model="queryParams.planStartTime"
                                            type="date" value-format="yyyy-MM-dd" placeholder="请选择计划开始时间">
                            </el-date-picker>
                        </el-form-item>
                        <el-form-item label="计划完成时间" prop="planEndTime">
                            <el-date-picker clearable v-model="queryParams.planEndTime"
                                            type="date" value-format="yyyy-MM-dd" placeholder="请选择计划完成时间">
                            </el-date-picker>
                        </el-form-item>
            <el-form-item label="工人id" prop="userId">
                <el-input v-model="queryParams.userId" placeholder="请输入工人id"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="姓名" prop="userName">
                <el-input v-model="queryParams.userName" placeholder="请输入姓名"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="单价" prop="money">
                <el-input v-model="queryParams.money" placeholder="请输入单价"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="分配数量" prop="count">
                <el-input v-model="queryParams.count" placeholder="请输入分配数量"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="总价" prop="allMoney">
                <el-input v-model="queryParams.allMoney" placeholder="请输入总价"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="剩余完成数量" prop="remainCount">
                <el-input v-model="queryParams.remainCount" placeholder="请输入剩余完成数量"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
                <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
            </el-form-item>
        </el-form>

        <el-row :gutter="10" class="mb8">
            <el-col :span="1.5">
                <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
                        v-hasPermi="['develop:GoodsSaledoGongxuUser:add']">新增</el-button>
            </el-col>
            <el-col :span="1.5">
                <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single"
                        @click="handleUpdate" v-hasPermi="['develop:GoodsSaledoGongxuUser:edit']">修改</el-button>
            </el-col>
            <el-col :span="1.5">
                <el-popconfirm title="确认删除选择的数据项？" @confirm="handleDelete({})">
                    <el-button slot="reference" type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple"
                               v-hasPermi="['develop:GoodsSaledoGongxuUser:remove']">删除</el-button>
                </el-popconfirm>
            </el-col>
            <el-col :span="1.5">
                <el-button type="warning" plain icon="el-icon-download" size="mini"
                        @click="handleExport" v-hasPermi="['develop:GoodsSaledoGongxuUser:export']">导出</el-button>
            </el-col>
            <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
        </el-row>

        <el-table border v-loading="loading" :data="dataList" @selection-change="handleSelectionChange" ref="table" :max-height="tableMaxHeight">
            <el-table-column type="selection" width="55" align="center"/>
                    <el-table-column label="${comment}" align="center" prop="id"/>
            <el-table-column label="序号" align="center" prop="xuhao"/>
            <el-table-column label="工序编码" align="center" prop="code"/>
            <el-table-column label="工序名称" align="center" prop="name"/>
            <el-table-column label="备注" align="center" prop="remark"/>
            <el-table-column label="图纸号" align="center" prop="shuoming"/>
            <el-table-column label="状态" align="center" prop="status"/>
            <el-table-column label="项目id" align="center" prop="projectId"/>
            <el-table-column label="项目编号" align="center" prop="projectCode"/>
            <el-table-column label="项目名称" align="center" prop="projectName"/>
            <el-table-column label="销售产品关联id" align="center" prop="saleId"/>
            <el-table-column label="产品id" align="center" prop="goodsId"/>
            <el-table-column label="工艺id" align="center" prop="gongyiId"/>
            <el-table-column label="工序id" align="center" prop="gongxuId"/>
            <el-table-column label="工艺编码" align="center" prop="gongyiCode"/>
            <el-table-column label="产品编码" align="center" prop="goodsCode"/>
            <el-table-column label="产品名称" align="center" prop="goodsName"  show-overflow-tooltip/>
            <el-table-column label="产品型号" align="center" prop="goodsModel"/>
          <!--  <el-table-column label="型号明细" align="center" prop="goodsBrand"/>-->
                    <el-table-column label="实际开始时间" align="center" prop="doStartTime" width="180">
                        <template slot-scope="scope">
                            <span>{{ parseTime(scope.row.doStartTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="实际完成时间" align="center" prop="doEndTime" width="180">
                        <template slot-scope="scope">
                            <span>{{ parseTime(scope.row.doEndTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="计划开始时间" align="center" prop="planStartTime" width="180">
                        <template slot-scope="scope">
                            <span>{{ parseTime(scope.row.planStartTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="计划完成时间" align="center" prop="planEndTime" width="180">
                        <template slot-scope="scope">
                            <span>{{ parseTime(scope.row.planEndTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
                        </template>
                    </el-table-column>
            <el-table-column label="工人id" align="center" prop="userId"/>
            <el-table-column label="姓名" align="center" prop="userName"/>
            <el-table-column label="单价" align="center" prop="money"/>
            <el-table-column label="分配数量" align="center" prop="count"/>
            <el-table-column label="总价" align="center" prop="allMoney"/>
            <el-table-column label="剩余完成数量" align="center" prop="remainCount"/>
            <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
                <template slot-scope="scope">
                    <el-button size="mini" type="text" icon="el-icon-edit"
                            @click="handleUpdate(scope.row)" v-hasPermi="['develop:GoodsSaledoGongxuUser:edit']">修改</el-button>
                    <el-popconfirm :title="`确认删除当前数据项？`" @confirm="handleDelete(scope.row)"
                                   style="margin-left: 10px;">
                        <el-button slot="reference" size="mini" type="text" icon="el-icon-delete"
                                   v-hasPermi="['develop:GoodsSaledoGongxuUser:remove']">删除</el-button>
                    </el-popconfirm>
                </template>
            </el-table-column>
        </el-table>

        <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum"
                :limit.sync="queryParams.pageSize" @pagination="getList"/>

        <goodsSaledoGongxuUser-form ref="form" @ok="getList"></goodsSaledoGongxuUser-form>
    </div>
</template>

<script>
    import { deleteAction, getAction } from '@/api/manage'
    import GoodsSaledoGongxuUserForm from '@/views/develop/goodsSaledoGongxuUser/module/GoodsSaledoGongxuUserForm'

    export default {
        name: "GoodsSaledoGongxuUserList",
        components: {
            GoodsSaledoGongxuUserForm,
        },
        data() {
            return {
                // 遮罩层
                loading: true,
                // 选中数组
                ids: [],
                // 非单个禁用
                single: true,
                // 非多个禁用
                multiple: true,
                // 显示搜索条件
                showSearch: true,
                // 总条数
                total: 0,
                // 订单产品工序分配任务表格数据
                dataList: [],
                // 查询参数
                queryParams: {
                    pageNum: 1,
                    pageSize: 10,
            xuhao: null,
            code: null,
            name: null,
            shuoming: null,
            status: null,
            projectId: null,
            projectCode: null,
            projectName: null,
            saleId: null,
            goodsId: null,
            gongyiId: null,
            gongxuId: null,
            gongyiCode: null,
            goodsCode: null,
            goodsName: null,
            goodsModel: null,
            goodsBrand: null,
            doStartTime: null,
            doEndTime: null,
            planStartTime: null,
            planEndTime: null,
            userId: null,
            userName: null,
            money: null,
            count: null,
            allMoney: null,
            remainCount: null
                },
                url: {
                    list:'/goodsSaledoGongxuUser/goodsSaledoGongxuUser/list',
                    remove:'/goodsSaledoGongxuUser/goodsSaledoGongxuUser/',
                    export:'/goodsSaledoGongxuUser/goodsSaledoGongxuUser/export',
                },
                tableMaxHeight: window.innerHeight - 320,
            };
        },
        created() {
            this.getList();
            window.addEventListener('resize', this.getTableHeight);
        },
        destroyed () {
            window.removeEventListener('resize', this.getTableHeight)
        },
        methods: {
            /** 查询订单产品工序分配任务列表 */
            getList() {
                this.loading = true;
                getAction(this.url.list, this.queryParams).then(response => {
                    this.dataList = response.rows;
                    this.total = response.total;
                    this.loading = false;
                });
            },
            getTableHeight () {
                this.tableHeight = window.innerHeight - 320
            },
            /** 搜索按钮操作 */
            handleQuery() {
                this.queryParams.pageNum = 1;
                this.getList();
            },
            /** 重置按钮操作 */
            resetQuery() {
                this.resetForm("queryForm");
                this.handleQuery();
            },
            // 多选框选中数据
            handleSelectionChange(selection) {
                this.ids = selection.map(item => item.id)
                this.single = selection.length !== 1
                this.multiple = !selection.length
            },
            /** 新增按钮操作 */
            handleAdd() {
                this.$refs.form.handleAdd();
            },
            /** 修改按钮操作 */
            handleUpdate(row) {
                this.$refs.form.handleUpdate(row);
            },
            /** 删除按钮操作 */
            handleDelete(row) {
                const ids = row.id || this.ids;
                deleteAction(this.url.remove, ids).then(response => {
                    this.getList();
                    this.$modal.msgSuccess("删除成功");
                }).catch(() => {});
            },
            /** 导出按钮操作 */
            handleExport() {
                this.download(this.url.export, {
                    ...this.queryParams
                }, `goodsSaledoGongxuUser_${new Date().getTime()}.xlsx`)
            },
  }
};
</script>
